// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_INV_WH
// * CreateDate    : 2013-12-20 23:31:45
// * Creater       : CodeSmith
// * LastChangeDate: 2013-12-20 23:31:45
// * LastChanger   : 2013-12-20 23:31:45
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Inv
{
    /// <summary>
    /// InvWh
    /// </summary>
    public partial class InvWhBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objInvWhEntity">Entity</param>
        /// <returns>Entity</returns>
        public static InvWhEntity GetInvWh(InvWhEntity objInvWhEntity)
        {
            return DataAccess.SelectSingle<InvWhEntity>(objInvWhEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objInvWhEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertInvWh(InvWhEntity objInvWhEntity)
        {
            return DataAccess.Insert(objInvWhEntity);
        }

        public static bool InsertInvWh(List<InvWhEntity> objInvWhEntityList)
        {
            return DataAccess.Insert(objInvWhEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objInvWhEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateInvWh(InvWhEntity objInvWhEntity)
        {
            return DataAccess.Update(objInvWhEntity);
        }

        public static bool UpdateInvWh(List<InvWhEntity> objInvWhEntityList)
        {
            return DataAccess.Update<InvWhEntity>(objInvWhEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objInvWhEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteInvWh(InvWhEntity objInvWhEntity)
        {
            return DataAccess.Delete(objInvWhEntity);
        }

        public static bool DeleteInvWh(List<InvWhEntity> objInvWhEntityList)
        {
            return DataAccess.Delete<InvWhEntity>(objInvWhEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetInvWhAll()
        {
            return DataAccess.SelectAllDataSet<InvWhEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<InvWhEntity> GetInvWhAllList()
        {
            return DataAccess.SelectAll<InvWhEntity>();
        }
        #endregion

        public static DataSet GetAllDsBySql(string sql)
        {
            return DataAccess.SelectDataSet(sql);
        }

        public static bool AddWh(InvWhEntity wh, List<InvWhLocationEntity> locs)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    DataAccess.Insert(wh, broker);
                    DataAccess.Insert(locs, broker);
                    broker.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    throw ex;
                }
            }

        }

        public static bool DelWh(InvWhEntity wh, List<InvWhLocationEntity> locs)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    if (locs != null)
                    {
                        DataAccess.Delete(locs, broker);
                    }
                    DataAccess.Delete(wh, broker);                    
                    broker.Commit();
                    return true;
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    throw ex;
                }
            }
        }

        public static List<InvWhEntity> GetInvWhAllList(InvWhEntity wh)
        {
            return DataAccess.Select<InvWhEntity>(wh);
        }
    }


}

